function getCookie(name) {
    var r = document.cookie.match("\\b" + name + "=([^;]*)\\b");
    return r ? r[1] : undefined;
}


$(function () {
    $(".balance button").click(function (e) {
        $('.recharge').show();
    })
	$('.money_form_off').click(function(){
		$('.recharge').hide();
	})
    $(".money_form").submit(function(e){
        e.preventDefault();
        var params={};

        $(this).serializeArray().map(function(x){
            params[x.name] = x.value;
        });
        
        $.ajax({
            url: "/web_user_money/",
            type: "post",
            contentType: "application/json",
            headers: {
                "X-CSRFToken": getCookie("csrf_token")
            },
            data: JSON.stringify(params),
            success: function (resp) {
                if (resp.errno == "0") {
                    // 添加成功
                    alert("添加成功")
                    window.location.reload()
                }else {
                    alert(resp.errmsg)
                }
            }
        })
    })
})